﻿namespace ACCOUNTING.LVY.Business
{
    using ACCOUNTING;
    using Microsoft.VisualBasic.CompilerServices;
    using System;
    using System.Data;
    using System.Runtime.InteropServices;
    using System.Windows.Forms;

    public class clsHopDong
    {
        private string mChucVu = "";
        private string mDaiDien = "";
        private string mDiaChi = "";
        private string mDienGiai = "";
        private string mDienThoai = "";
        private string mDoiTuong = "";
        private string mFax = "";
        private string mHinhThucTT = "";
        private string mKhoa = "";
        private string mLoaiHopDong = "";
        private string mLoaiTien = "";
        private string mMaSoThue = "";
        private string mNgayHopDong = "";
        private string mNgayThanhLy = "";
        private string mNgayThanhToan = "";
        private string mSoHopDong = "";
        private double mTienThue = 0.0;
        private double mTienThueNT = 0.0;
        private double mTongCong = 0.0;
        private double mTongCongNT = 0.0;
        private double mTongTriGia = 0.0;
        private double mTongTriGiaNT = 0.0;
        private double mTyGia = 0.0;
        private int mTyLeThue = 0;

        public void ClearTemp(string pKeyTable)
        {
            string commandText = "DELETE FROM CO_HopDongChiTietTmp WHERE KhoaHopDong = '" + pKeyTable.Trim() + "'";
            DBHelper.ExecuteNonQuery(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[0]);
        }

        public bool DeleteData(string strKhoa)
        {
            bool flag=false;
            IDataParameter[] commandParameters = new IDataParameter[2];
            try
            {
                commandParameters[0] = DBHelper.createParameter("@Khoa", DbType.Int64, ParameterDirection.Input, strKhoa);
                commandParameters[1] = DBHelper.createParameter("@pError", DbType.Double, ParameterDirection.Output, 0);
                int num = DBHelper.ExecuteNonQuery(modGeneral.ConnectionString, CommandType.StoredProcedure, "CO_sp_HopDongDel", commandParameters);
                if (Microsoft.VisualBasic.CompilerServices.Operators.ConditionalCompareObjectNotEqual(commandParameters[1].Value, 0, false))
                {
                    return false;
                }
                flag = true;
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message.ToString());
                flag = false;
                ProjectData.ClearProjectError();
                return flag;
                ProjectData.ClearProjectError();
            }
            return flag;
        }

        public DataTable GetListDetails(string strKhoa)
        {
            DataTable table;
            try
            {
                string commandText = " SELECT CT.*  FROM CO_HopDongChiTiet CT WHERE CT.KhoaHopDong = '" + strKhoa + "'";
                table = DBHelper.ExecuteDataset(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[0]).Tables[0];
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message);
                table = null;
                ProjectData.ClearProjectError();
                return table;
                ProjectData.ClearProjectError();
            }
            return table;
        }

        public DataTable GetListHopDong(string strCondition = "")
        {
            DataTable table;
            string str2 = "";
            try
            {
                if (strCondition.Trim() != "")
                {
                    str2 = " WHERE " + strCondition;
                }
                string commandText = "SELECT HD.Khoa, HD.SoHopDong, dbo.Char2Date(HD.NgayHopDong) as NgayHopDong, DT.TenViet as NhaCungCap, HD.TongTriGiaNT , HD.TienThueNT, HD.DienGiai FROM CO_HopDong HD LEFT JOIN DM_DoiTuong DT ON HD.DoiTuong = DT.Khoa " + str2 + " ORDER BY HD.NgayHopDong, HD.SoHopDong ";
                table = DBHelper.ExecuteDataset(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[0]).Tables[0];
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message);
                table = null;
                ProjectData.ClearProjectError();
                return table;
                ProjectData.ClearProjectError();
            }
            return table;
        }

        public bool IsDuplicateVoucherNo(string strVoucherNo, string strKeyTable)
        {
            string commandText = "SELECT * FROM CO_HopDong Where Rtrim(SoHopDong) = '" + strVoucherNo.Trim() + "' AND Khoa <> '" + strKeyTable + "'";
            return (DBHelper.ExecuteDataset(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[0]).Tables[0].Rows.Count > 0);
        }

        public bool Load(string pKhoa)
        {
            bool flag=false;
            try
            {
                string commandText = "SELECT * FROM CO_HopDong WHERE Khoa = '" + pKhoa + "'";
                IDataReader dataReader = DBHelper.ExecuteReader(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[0]);
                if (dataReader.Read())
                {
                    this.mKhoa = Conversions.ToString(modGeneral.GetValue(dataReader, 0, modGeneral.typeOfColumn.GetString));
                    this.mLoaiHopDong = Conversions.ToString(modGeneral.GetValue(dataReader, 1, modGeneral.typeOfColumn.GetString));
                    this.mSoHopDong = Conversions.ToString(modGeneral.GetValue(dataReader, 2, modGeneral.typeOfColumn.GetString));
                    this.mNgayHopDong = Conversions.ToString(modGeneral.GetValue(dataReader, 3, modGeneral.typeOfColumn.GetString));
                    this.mLoaiTien = Conversions.ToString(modGeneral.GetValue(dataReader, 4, modGeneral.typeOfColumn.GetString));
                    this.mTyGia = Conversions.ToDouble(modGeneral.GetValue(dataReader, 5, modGeneral.typeOfColumn.GetDecimal));
                    this.mHinhThucTT = Conversions.ToString(modGeneral.GetValue(dataReader, 6, modGeneral.typeOfColumn.GetString));
                    this.mTyLeThue = Conversions.ToInteger(modGeneral.GetValue(dataReader, 7, modGeneral.typeOfColumn.GetInt32));
                    this.mNgayThanhToan = Conversions.ToString(modGeneral.GetValue(dataReader, 8, modGeneral.typeOfColumn.GetString));
                    this.mNgayThanhLy = Conversions.ToString(modGeneral.GetValue(dataReader, 9, modGeneral.typeOfColumn.GetString));
                    this.mDoiTuong = Conversions.ToString(modGeneral.GetValue(dataReader, 10, modGeneral.typeOfColumn.GetString));
                    this.mDaiDien = Conversions.ToString(modGeneral.GetValue(dataReader, 11, modGeneral.typeOfColumn.GetString));
                    this.mChucVu = Conversions.ToString(modGeneral.GetValue(dataReader, 12, modGeneral.typeOfColumn.GetString));
                    this.mDiaChi = Conversions.ToString(modGeneral.GetValue(dataReader, 13, modGeneral.typeOfColumn.GetString));
                    this.mMaSoThue = Conversions.ToString(modGeneral.GetValue(dataReader, 14, modGeneral.typeOfColumn.GetString));
                    this.mDienThoai = Conversions.ToString(modGeneral.GetValue(dataReader, 15, modGeneral.typeOfColumn.GetString));
                    this.mFax = Conversions.ToString(modGeneral.GetValue(dataReader, 0x10, modGeneral.typeOfColumn.GetString));
                    this.mDienGiai = Conversions.ToString(modGeneral.GetValue(dataReader, 0x11, modGeneral.typeOfColumn.GetString));
                    this.mTongTriGia = Conversions.ToDouble(modGeneral.GetValue(dataReader, 0x12, modGeneral.typeOfColumn.GetDecimal));
                    this.mTongTriGiaNT = Conversions.ToDouble(modGeneral.GetValue(dataReader, 0x13, modGeneral.typeOfColumn.GetDecimal));
                    this.mTienThue = Conversions.ToDouble(modGeneral.GetValue(dataReader, 20, modGeneral.typeOfColumn.GetDecimal));
                    this.mTienThueNT = Conversions.ToDouble(modGeneral.GetValue(dataReader, 0x15, modGeneral.typeOfColumn.GetDecimal));
                    this.mTongCong = Conversions.ToDouble(modGeneral.GetValue(dataReader, 0x16, modGeneral.typeOfColumn.GetDecimal));
                    this.mTongCongNT = Conversions.ToDouble(modGeneral.GetValue(dataReader, 0x17, modGeneral.typeOfColumn.GetDecimal));
                }
                dataReader.Close();
                flag = true;
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message.ToString());
                flag = false;
                ProjectData.ClearProjectError();
                return flag;
                ProjectData.ClearProjectError();
            }
            return flag;
        }

        public bool Save()
        {
            bool flag=false;
            IDataParameter[] commandParameters = new IDataParameter[0x19];
            try
            {
                commandParameters[0] = DBHelper.createParameter("@Khoa", DbType.Int64, ParameterDirection.Input, this.mKhoa);
                commandParameters[1] = DBHelper.createParameter("@LoaiHopDong", DbType.Int64, ParameterDirection.Input, this.mLoaiHopDong);
                commandParameters[2] = DBHelper.createParameter("@SoHopDong", DbType.Int64, ParameterDirection.Input, this.mSoHopDong);
                commandParameters[3] = DBHelper.createParameter("@NgayHopDong", DbType.Int64, ParameterDirection.Input, this.mNgayHopDong);
                commandParameters[4] = DBHelper.createParameter("@LoaiTien", DbType.Int64, ParameterDirection.Input, this.mLoaiTien);
                commandParameters[5] = DBHelper.createParameter("@TyGia", DbType.Date, ParameterDirection.Input, this.mTyGia);
                commandParameters[6] = DBHelper.createParameter("@HinhThucTT", DbType.Int64, ParameterDirection.Input, this.mHinhThucTT);
                commandParameters[7] = DBHelper.createParameter("@TyLeThue", DbType.Double, ParameterDirection.Input, this.mTyLeThue);
                commandParameters[8] = DBHelper.createParameter("@NgayThanhToan", DbType.Int64, ParameterDirection.Input, this.mNgayThanhToan);
                commandParameters[9] = DBHelper.createParameter("@NgayThanhLy", DbType.Int64, ParameterDirection.Input, this.mNgayThanhLy);
                commandParameters[10] = DBHelper.createParameter("@DoiTuong", DbType.Int64, ParameterDirection.Input, this.mDoiTuong);
                commandParameters[11] = DBHelper.createParameter("@DaiDien", DbType.Int64, ParameterDirection.Input, this.mDaiDien);
                commandParameters[12] = DBHelper.createParameter("@ChucVu", DbType.Int64, ParameterDirection.Input, this.mChucVu);
                commandParameters[13] = DBHelper.createParameter("@DiaChi", DbType.Int64, ParameterDirection.Input, this.mDiaChi);
                commandParameters[14] = DBHelper.createParameter("@MaSoThue", DbType.Int64, ParameterDirection.Input, this.mMaSoThue);
                commandParameters[15] = DBHelper.createParameter("@DienThoai", DbType.Int64, ParameterDirection.Input, this.mDienThoai);
                commandParameters[0x10] = DBHelper.createParameter("@Fax", DbType.Int64, ParameterDirection.Input, this.mFax);
                commandParameters[0x11] = DBHelper.createParameter("@DienGiai", DbType.Int64, ParameterDirection.Input, this.mDienGiai);
                commandParameters[0x12] = DBHelper.createParameter("@TongTriGia", DbType.Date, ParameterDirection.Input, this.mTongTriGia);
                commandParameters[0x13] = DBHelper.createParameter("@TongTriGiaNT", DbType.Date, ParameterDirection.Input, this.mTongTriGiaNT);
                commandParameters[20] = DBHelper.createParameter("@TienThue", DbType.Date, ParameterDirection.Input, this.mTienThue);
                commandParameters[0x15] = DBHelper.createParameter("@TienThueNT", DbType.Date, ParameterDirection.Input, this.mTienThueNT);
                commandParameters[0x16] = DBHelper.createParameter("@TongCong", DbType.Date, ParameterDirection.Input, this.mTongCong);
                commandParameters[0x17] = DBHelper.createParameter("@TongCongNT", DbType.Date, ParameterDirection.Input, this.mTongCongNT);
                commandParameters[0x18] = DBHelper.createParameter("@pError", DbType.Double, ParameterDirection.Output, 0);
                int num = DBHelper.ExecuteNonQuery(modGeneral.ConnectionString, CommandType.StoredProcedure, "CO_sp_HopDong", commandParameters);
                if (Microsoft.VisualBasic.CompilerServices.Operators.ConditionalCompareObjectEqual(commandParameters[0x18].Value, 0, false))
                {
                    return true;
                }
                flag = false;
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message.ToString());
                flag = false;
                ProjectData.ClearProjectError();
                return flag;
                ProjectData.ClearProjectError();
            }
            return flag;
        }

        public string ChucVu
        {
            get
            {
                return this.mChucVu;
            }
            set
            {
                this.mChucVu = value;
            }
        }

        public string DaiDien
        {
            get
            {
                return this.mDaiDien;
            }
            set
            {
                this.mDaiDien = value;
            }
        }

        public string DiaChi
        {
            get
            {
                return this.mDiaChi;
            }
            set
            {
                this.mDiaChi = value;
            }
        }

        public string DienGiai
        {
            get
            {
                return this.mDienGiai;
            }
            set
            {
                this.mDienGiai = value;
            }
        }

        public string DienThoai
        {
            get
            {
                return this.mDienThoai;
            }
            set
            {
                this.mDienThoai = value;
            }
        }

        public string DoiTuong
        {
            get
            {
                return this.mDoiTuong;
            }
            set
            {
                this.mDoiTuong = value;
            }
        }

        public string Fax
        {
            get
            {
                return this.mFax;
            }
            set
            {
                this.mFax = value;
            }
        }

        public string HinhThucTT
        {
            get
            {
                return this.mHinhThucTT;
            }
            set
            {
                this.mHinhThucTT = value;
            }
        }

        public string Khoa
        {
            get
            {
                return this.mKhoa;
            }
            set
            {
                this.mKhoa = value;
            }
        }

        public string LoaiHopDong
        {
            get
            {
                return this.mLoaiHopDong;
            }
            set
            {
                this.mLoaiHopDong = value;
            }
        }

        public string LoaiTien
        {
            get
            {
                return this.mLoaiTien;
            }
            set
            {
                this.mLoaiTien = value;
            }
        }

        public string MaSoThue
        {
            get
            {
                return this.mMaSoThue;
            }
            set
            {
                this.mMaSoThue = value;
            }
        }

        public string NgayHopDong
        {
            get
            {
                return this.mNgayHopDong;
            }
            set
            {
                this.mNgayHopDong = value;
            }
        }

        public string NgayThanhLy
        {
            get
            {
                return this.mNgayThanhLy;
            }
            set
            {
                this.mNgayThanhLy = value;
            }
        }

        public string NgayThanhToan
        {
            get
            {
                return this.mNgayThanhToan;
            }
            set
            {
                this.mNgayThanhToan = value;
            }
        }

        public string SoHopDong
        {
            get
            {
                return this.mSoHopDong;
            }
            set
            {
                this.mSoHopDong = value;
            }
        }

        public double TienThue
        {
            get
            {
                return this.mTienThue;
            }
            set
            {
                this.mTienThue = value;
            }
        }

        public double TienThueNT
        {
            get
            {
                return this.mTienThueNT;
            }
            set
            {
                this.mTienThueNT = value;
            }
        }

        public double TongCong
        {
            get
            {
                return this.mTongCong;
            }
            set
            {
                this.mTongCong = value;
            }
        }

        public double TongCongNT
        {
            get
            {
                return this.mTongCongNT;
            }
            set
            {
                this.mTongCongNT = value;
            }
        }

        public double TongTriGia
        {
            get
            {
                return this.mTongTriGia;
            }
            set
            {
                this.mTongTriGia = value;
            }
        }

        public double TongTriGiaNT
        {
            get
            {
                return this.mTongTriGiaNT;
            }
            set
            {
                this.mTongTriGiaNT = value;
            }
        }

        public double TyGia
        {
            get
            {
                return this.mTyGia;
            }
            set
            {
                this.mTyGia = value;
            }
        }

        public int TyLeThue
        {
            get
            {
                return this.mTyLeThue;
            }
            set
            {
                this.mTyLeThue = value;
            }
        }
    }
}

